package com.zhc.dejingapi.service.dingtalk.impl;

import com.zhc.dejingapi.pojo.dingtalk.DingTalkApiInfo;
import com.zhc.dejingapi.service.dingtalk.IProcessDingCallBackDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import shade.com.alibaba.fastjson2.JSONObject;

@Slf4j
@Service
public class ProcessDingCallBackDataServiceImpl implements IProcessDingCallBackDataService {

    @Autowired
    private DingTalkApiInfo dingTalkApiInfo;

    private final JdbcTemplate dingDBJdbcTemplate;

    public ProcessDingCallBackDataServiceImpl(
            @Qualifier("dingDataJdbcTemplate") JdbcTemplate dingDBJdbcTemplate) {
        this.dingDBJdbcTemplate = dingDBJdbcTemplate;
    }

    @Override
    public Boolean ProcessData(String eventId,String eventType,Long bornTime,JSONObject jsonData) {

        String strSql="insert into ding_msgcallback(eventId,eventType,bornTime,msgContent) values(?,?,?,?)";
        try {
            dingDBJdbcTemplate.update(strSql,eventId,eventType,bornTime,jsonData.toJSONString());
            return  true;
        } catch (Exception e) {
            e.printStackTrace();
            log.error("插入钉钉回调数据失败",e);
            return false;
        }

    }
}
